import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
import { GroupService } from './group.service';
import { AuthGuard } from '@nestjs/passport';
import { returnFail, returnSuccess } from 'src/common/response';
import { CODE, TRes } from 'src/common/base';
import { User } from '@prisma/client';

@Controller('/api/group')
@UseGuards(AuthGuard('jwt'))
export class GroupController {
  constructor(private readonly groupService: GroupService) {}


  @Get('/groupUser')
  async getGroupUsers(@Query('groupId') groupId: string) {
    if (!groupId) {
      return returnFail(CODE.PARAMERROR, 'groupId 不能为空')
    }
    const userList: TRes<User[]> = await this.groupService.getGroupUsers(groupId);
    if (userList.sql) {
      return returnFail(CODE.SQLERROR, userList.msg)
    }
    return returnSuccess(userList.msg, userList.data)
  }
}
